package com.wyh.day05.work;

/**
 * @author 王艺豪
 * @version 1.0
 */
public class work04 {
    public static void main(String[] args) {

        //递归
        System.out.println(sum1(100));
        //循环
        System.out.println(sum2(100));
    }

    //实现 1+2+3+...+n
    //递归
    public static int sum1(int num) {
        if (num == 1) return 1;
        return num + sum1(num - 1);
    }

    //for循环
    public static int sum2(int num) {
        int sum = 0;
        for (int i = 1; i <= num; i++) {
            sum += i;
        }
        return sum;
    }
}
